package com.reptile.handle;

import com.alibaba.fastjson.JSON;
import com.common.constant.YsConstant;
import com.reptile.context.BaseContext;
import com.reptile.dto.NewsDTO;
import com.reptile.mes.DingDingHelp;
import com.reptile.service.execute.*;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

/**
 * 新闻定时任务处理类
 *
 * @author songyafei
 */
@Slf4j
@Component
public class YsNewsHandle {

    @Resource
    private DingDingHelp dingDingHelp;

    /**
     * 爬取新浪新闻数据
     */
    @XxlJob("YsReptileXLNewsHandler")
    void XLNewsExecute() throws Exception {
        log.info("开始爬取新浪新闻数据！");
        BaseContext baseContext = new BaseContext(new XlBaseExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        //规定新闻条数 发送的条数太多钉钉顶不住
        result = result.subList(0, 10);
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取新浪新闻数据结束！{}", JSON.toJSONString(result));
    }

    /**
     * 爬取比特范新闻数据
     */
    @XxlJob("YsReptileBTCNewsHandler")
    void BTCNewsExecute() throws Exception {
        log.info("开始爬取比特范新闻数据！");
        BaseContext baseContext = new BaseContext(new BtfBaseExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取比特范新闻数据结束！{}", JSON.toJSONString(result));
    }


    /**
     * 爬取百度国际新闻数据
     */
    @XxlJob("YsReptileBaiDuNewsHandler")
    void BaiDuNewsExecute() throws Exception {
        log.info("爬取百度国际新闻数据！");
        BaseContext baseContext = new BaseContext(new BaiDuBaseExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取百度国际新闻数据！", result);
    }

    /**
     * 爬取澎湃精选新闻数据
     */
    @XxlJob("YsPPaiBaseNewsHandler")
    public void PPaiNewsExecute() throws Exception {
        log.info("爬取澎湃精选新闻数据开始！");
        BaseContext baseContext = new BaseContext(new PPaiBaseExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取澎湃精选新闻结束！{}", result);
    }

    /**
     * 爬取雷锋网业界资讯数据
     */
    @XxlJob("LeiFIndustryNewsHandler")
    public void LeiFIndustryNewsExecute() throws Exception {
        log.info("爬取雷锋网业界资讯数据开始！");
        BaseContext baseContext = new BaseContext(new LeiFIndustryExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取雷锋网业界资讯数据结束！{}", result);
    }
}
